﻿using Super.Admin.ViewModels.Base;

namespace Super.Admin.Models.Announcement
{
    public class AnnouncementBaseModel : ViewModelBase
    {
        /// <summary>
        /// 公告索引
        /// </summary>
        public int Index { get; set; }
        /// <summary>
        /// 公告ID
        /// </summary>
        public int Id { get; set; }
        private string _title;
        /// <summary>
        /// 公告标题
        /// </summary>
        public string Title
        {
            get { return _title; }
            set
            {
                SetProperty<string>(ref _title, value);
                ValidateContent();
            }
        }
        private string _content;
        /// <summary>
        /// 公告内容
        /// </summary>
        public string Content
        {
            get { return _content; }
            set { SetProperty<string>(ref _content, value); }
        }
        /// <summary>
        /// 创建时间
        /// </summary>
        public string CreateTime { get; set; }
        /// <summary>
        /// 更新时间
        /// </summary>
        public string UpdateTime { get; set; }
        /// <summary>
        /// 创建用户ID
        /// </summary>
        public int CreateUserId { get; set; }
        /// <summary>
        /// 更新用户ID
        /// </summary>
        public int? UpdateUserId { get; set; }
        /// <summary>
        /// 0、发布 1、草稿
        /// </summary>
        public int Status { get; set; }
        /// <summary>
        /// 发布时间
        /// </summary>
        public string PublishTime { get; set; }
        /// <summary>
        /// 发布用户ID
        /// </summary>
        public int? PublishUserId { get; set; }
        /// <summary>
        /// 验证内容
        /// </summary>
        public override void ValidateContent()
        {
            if (string.IsNullOrEmpty(Title))
            {
                AddError("标题不能为空", nameof(Title));
            }
            else
            {
                ClearErrors(nameof(Title));
            }
            base.ValidateContent();
        }
    }
}
